package com.qf.nacos.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.qf.nacos.client.ProducerClient;
import com.qf.nacos.mapper.ConsumerMapper;
import com.qf.nacos.service.ConsumerService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ConsumerServiceImpl implements ConsumerService {

    @Resource
    private ConsumerMapper consumerMapper;

    @Resource
    private ProducerClient producerClient;

    @Override
    @SentinelResource(value = "serviceTestA")
    public String testA() {
        return "xxxxxxxxxxxxx";
    }

    @Override
    @GlobalTransactional
    public void transfer() {
        // 李四加1000
        producerClient.transfer();

        int i = 1 / 0;

        // 张三减1000
        consumerMapper.jianQian();
    }
}
